<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/*---------------------------------------------------------------------------*/</span><span class="WHIT">
<span class='line'>  2</span> </span><span class="COMM">/** 
<span class='line'>  3</span>  * @fileOverview Implementa classes para manipular captura de audio via HTML5.
<span class='line'>  4</span>  * 
<span class='line'>  5</span>  * @author Robson Martins (robson@robsonmartins.com)
<span class='line'>  6</span>  * @version 1.0
<span class='line'>  7</span>  */</span><span class="WHIT">
<span class='line'>  8</span> </span><span class="COMM">/*---------------------------------------------------------------------------*/</span><span class="WHIT">
<span class='line'>  9</span> </span><span class="COMM">/**
<span class='line'> 10</span>  * @class Implementa Captura de Audio via HTML5/JavaScript.
<span class='line'> 11</span>  * @constructor
<span class='line'> 12</span>  * @description Cria um objeto para Captura de Audio via HTML5.
<span class='line'> 13</span>  */</span><span class="WHIT">
<span class='line'> 14</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">Speech</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 15</span> 
<span class='line'> 16</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">DEFAULT_SILENCE_LEVEL</span><span class="WHIT">  </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">20</span><span class="PUNC">;</span><span class="WHIT">   </span><span class="COMM">// dB</span><span class="WHIT">
<span class='line'> 17</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">DEFAULT_SILENCE_LENGTH</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">200</span><span class="PUNC">;</span><span class="WHIT">  </span><span class="COMM">// ms</span><span class="WHIT">
<span class='line'> 18</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">DEFAULT_SAMPLE_RATE</span><span class="WHIT">    </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">44100</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="COMM">// Hz</span><span class="WHIT">
<span class='line'> 19</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">RESAMPLE_FACTOR</span><span class="WHIT">        </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 20</span> </span><span class="WHIT">	
<span class='line'> 21</span> 	</span><span class="NAME">window.AudioContext</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> 
<span class='line'> 22</span> 		</span><span class="NAME">window.AudioContext</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">window.webkitAudioContext</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT">
<span class='line'> 23</span> </span><span class="WHIT">		</span><span class="NAME">window.mozAudioContext</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 24</span> </span><span class="WHIT">	</span><span class="NAME">navigator.getUserMedia</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> 
<span class='line'> 25</span> 		</span><span class="NAME">navigator.getUserMedia</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">navigator.webkitGetUserMedia</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT">
<span class='line'> 26</span> </span><span class="WHIT">    	</span><span class="NAME">navigator.mozGetUserMedia</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">navigator.msGetUserMedia</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 27</span> </span><span class="WHIT">	
<span class='line'> 28</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">onSuccess</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">  
<span class='line'> 29</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">onError</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 30</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">recording</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 31</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">status</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="COMM">/* 0: wait for sound; 1: sound; 2: silence found */</span><span class="WHIT">
<span class='line'> 32</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">context</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 33</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">volume</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 34</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">localStream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 35</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">audioInput</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 36</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">recorder</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 37</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">leftchannel</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 38</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rightchannel</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 39</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">recordingLength</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 40</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">leftBuffer</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 41</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rightBuffer</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 42</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">monoBuffer</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 43</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">silenceFrames</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 44</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">silenceLevel</span><span class="WHIT">  </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">DEFAULT_SILENCE_LEVEL</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 45</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">silenceLength</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">DEFAULT_SILENCE_LENGTH</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 46</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">sampleRate</span><span class="WHIT">    </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">DEFAULT_SAMPLE_RATE</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="WHIT">    
<span class='line'> 48</span> 	</span><span class="COMM">/**
<span class='line'> 49</span> 	 * @memberOf Speech 
<span class='line'> 50</span> 	 * @function
<span class='line'> 51</span> 	 * @description Obtem o nivel de silencio configurado.
<span class='line'> 52</span> 	 * @returns {Number} Nivel de silencio, em dB.
<span class='line'> 53</span> 	 */</span><span class="WHIT">
<span class='line'> 54</span> </span><span class="WHIT">    </span><span class="NAME">this.getSilenceLevel</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 55</span> </span><span class="WHIT">    	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">silenceLevel</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 57</span> 
<span class='line'> 58</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 59</span> 	 * @memberOf Speech 
<span class='line'> 60</span> 	 * @function
<span class='line'> 61</span> 	 * @description Configura o nivel de silencio.
<span class='line'> 62</span> 	 * @param {Number} level Nivel de silencio, em dB.
<span class='line'> 63</span> 	 * @returns {Number} Nivel de silencio configurado, em dB.
<span class='line'> 64</span> 	 */</span><span class="WHIT">
<span class='line'> 65</span> </span><span class="WHIT">    </span><span class="NAME">this.setSilenceLevel</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">level</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 66</span> </span><span class="WHIT">    	</span><span class="NAME">silenceLevel</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">level</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="WHIT">    	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">getSilenceLevel</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 69</span> </span><span class="WHIT">    
<span class='line'> 70</span> 	</span><span class="COMM">/**
<span class='line'> 71</span> 	 * @memberOf Speech 
<span class='line'> 72</span> 	 * @function
<span class='line'> 73</span> 	 * @description Obtem a duracao de silencio configurada.
<span class='line'> 74</span> 	 * @returns {Number} Duracao de silencio, em ms.
<span class='line'> 75</span> 	 */</span><span class="WHIT">
<span class='line'> 76</span> </span><span class="WHIT">    </span><span class="NAME">this.getSilenceLength</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 77</span> </span><span class="WHIT">    	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">silenceLength</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 78</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 79</span> 
<span class='line'> 80</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 81</span> 	 * @memberOf Speech 
<span class='line'> 82</span> 	 * @function
<span class='line'> 83</span> 	 * @description Configura a duracao de silencio.
<span class='line'> 84</span> 	 * @param {Number} length Duracao de silencio, em ms.
<span class='line'> 85</span> 	 * @returns {Number} Duracao de silencio configurada, em ms.
<span class='line'> 86</span> 	 */</span><span class="WHIT">
<span class='line'> 87</span> </span><span class="WHIT">    </span><span class="NAME">this.setSilenceLength</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">length</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 88</span> </span><span class="WHIT">    	</span><span class="NAME">getSilenceLength</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="WHIT">    	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">getSilenceLength</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 90</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 91</span> 
<span class='line'> 92</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 93</span> 	 * @memberOf Speech 
<span class='line'> 94</span> 	 * @function
<span class='line'> 95</span> 	 * @description Inicia captura de audio.
<span class='line'> 96</span> 	 * @param { function ( DataView audio ) } [onSuccessCallback] Callback do evento
<span class='line'> 97</span> 	 *   disparado quando ha audio capturado disponivel.
<span class='line'> 98</span> 	 * @param { function ( Event e ) } [onErrorCallback] Callback do evento disparado
<span class='line'> 99</span> 	 *   caso haja algum erro na captura.
<span class='line'>100</span> 	 */</span><span class="WHIT">
<span class='line'>101</span> </span><span class="WHIT">    </span><span class="NAME">this.startCapture</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">onSuccessCallback</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">onErrorCallback</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>102</span> </span><span class="WHIT">		</span><span class="NAME">onSuccess</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">onSuccessCallback</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>103</span> </span><span class="WHIT">		</span><span class="NAME">onError</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">onErrorCallback</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>104</span> </span><span class="WHIT">	    </span><span class="NAME">recording</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>105</span> </span><span class="WHIT">	    </span><span class="NAME">initRecord</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>106</span> </span><span class="WHIT">		</span><span class="NAME">navigator.getUserMedia</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="NAME">audio</span><span class="PUNC">:</span><span class="KEYW">true</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">onCapture</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">onError</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>107</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>108</span> 
<span class='line'>109</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'>110</span> 	 * @memberOf Speech 
<span class='line'>111</span> 	 * @function
<span class='line'>112</span> 	 * @description Encerra captura de audio.
<span class='line'>113</span> 	 */</span><span class="WHIT">
<span class='line'>114</span> </span><span class="WHIT">    </span><span class="NAME">this.stopCapture</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>115</span> </span><span class="WHIT">	    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">recording</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> 
<span class='line'>116</span> 		    </span><span class="NAME">recording</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>117</span> </span><span class="WHIT">		    </span><span class="NAME">localStream.stop</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>118</span> </span><span class="WHIT">	    	</span><span class="NAME">pauseRecord</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>119</span> </span><span class="WHIT">	    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>120</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>121</span> </span><span class="WHIT">    
<span class='line'>122</span>     </span><span class="COMM">/** 
<span class='line'>123</span>      * @private 
<span class='line'>124</span> 	 * @function
<span class='line'>125</span> 	 * @description Limpa buffers para iniciar captura de audio.
<span class='line'>126</span>      */</span><span class="WHIT">
<span class='line'>127</span> </span><span class="WHIT">    </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">initRecord</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>128</span> </span><span class="WHIT">        </span><span class="NAME">leftchannel</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>129</span> </span><span class="WHIT">        </span><span class="NAME">rightchannel</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>130</span> </span><span class="WHIT">    	</span><span class="NAME">recordingLength</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>131</span> </span><span class="WHIT">    	</span><span class="NAME">silenceFrames</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>132</span> </span><span class="WHIT">    	</span><span class="NAME">status</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>133</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>134</span> </span><span class="WHIT">    
<span class='line'>135</span>     </span><span class="COMM">/** 
<span class='line'>136</span>      * @private 
<span class='line'>137</span> 	 * @function
<span class='line'>138</span> 	 * @description Salva buffer de captura no formato WAV, e dispara o evento onSuccess.
<span class='line'>139</span>      */</span><span class="WHIT">
<span class='line'>140</span> </span><span class="WHIT">    </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">pauseRecord</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>141</span> </span><span class="WHIT">	    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">audio</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pcmToWav</span><span class="PUNC">(</span><span class="NAME">leftchannel</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">rightchannel</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">recordingLength</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">sampleRate</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>142</span> </span><span class="WHIT">	    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">audio</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">onSuccess</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">onSuccess</span><span class="PUNC">(</span><span class="NAME">audio</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>143</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>144</span> </span><span class="WHIT">    
<span class='line'>145</span>     </span><span class="COMM">/** 
<span class='line'>146</span>      * @private 
<span class='line'>147</span> 	 * @function
<span class='line'>148</span> 	 * @description Callback da funcao getUserMedia(), chamado quando ha' dados na
<span class='line'>149</span> 	 *   stream de captura de audio.
<span class='line'>150</span> 	 * @param {MediaStream} stream Objeto que contem dados do audio capturado.
<span class='line'>151</span>      */</span><span class="WHIT">
<span class='line'>152</span> </span><span class="WHIT">	</span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">onCapture</span><span class="PUNC">(</span><span class="NAME">stream</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>153</span> </span><span class="WHIT">		</span><span class="NAME">localStream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">stream</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>154</span> </span><span class="WHIT">	    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">recording</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>155</span> </span><span class="WHIT">	    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">bufferSize</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">2048</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>156</span> </span><span class="WHIT">	    </span><span class="NAME">context</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">window.AudioContext</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>157</span> </span><span class="WHIT">	    </span><span class="NAME">volume</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">context.createGain</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>158</span> </span><span class="WHIT">	    </span><span class="NAME">audioInput</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">context.createMediaStreamSource</span><span class="PUNC">(</span><span class="NAME">stream</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>159</span> </span><span class="WHIT">	    </span><span class="NAME">sampleRate</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">context.sampleRate</span><span class="PUNC">;</span><span class="WHIT"> 
<span class='line'>160</span> 	    </span><span class="NAME">audioInput.connect</span><span class="PUNC">(</span><span class="NAME">volume</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>161</span> </span><span class="WHIT">	    </span><span class="NAME">recorder</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">context.createJavaScriptNode</span><span class="PUNC">(</span><span class="NAME">bufferSize</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>162</span> </span><span class="WHIT">	    </span><span class="NAME">volume.connect</span><span class="PUNC">(</span><span class="NAME">recorder</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>163</span> </span><span class="WHIT">	    </span><span class="NAME">recorder.connect</span><span class="PUNC">(</span><span class="NAME">context.destination</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> 
<span class='line'>164</span> 	    
<span class='line'>165</span> 	    </span><span class="COMM">/** @private */</span><span class="WHIT">
<span class='line'>166</span> </span><span class="WHIT">	    </span><span class="NAME">recorder.onaudioprocess</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">audio</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>167</span> </span><span class="WHIT">	        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">left</span><span class="WHIT">  </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">audio.inputBuffer.getChannelData</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>168</span> </span><span class="WHIT">	        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">right</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">audio.inputBuffer.getChannelData</span><span class="PUNC">(</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>169</span> </span><span class="WHIT">	        </span><span class="NAME">leftchannel.push</span><span class="PUNC">(</span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Float32Array</span><span class="PUNC">(</span><span class="NAME">left</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>170</span> </span><span class="WHIT">	        </span><span class="NAME">rightchannel.push</span><span class="PUNC">(</span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Float32Array</span><span class="PUNC">(</span><span class="NAME">right</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>171</span> </span><span class="WHIT">	        </span><span class="NAME">recordingLength</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">bufferSize</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>172</span> </span><span class="WHIT">	        
<span class='line'>173</span> 	        </span><span class="COMM">// se detectou silencio: pausa, retorna dados gravados e continua captura.</span><span class="WHIT">
<span class='line'>174</span> </span><span class="WHIT">	        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">detectSilence</span><span class="PUNC">(</span><span class="NAME">left</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">right</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">silenceLevel</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">silenceLength</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>175</span> </span><span class="WHIT">	        	</span><span class="NAME">pauseRecord</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> 
<span class='line'>176</span> 	        	</span><span class="NAME">initRecord</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>177</span> </span><span class="WHIT">	        </span><span class="PUNC">}</span><span class="WHIT"> 
<span class='line'>178</span> 	    </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>179</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>180</span> </span><span class="WHIT">	
<span class='line'>181</span>     </span><span class="COMM">/** 
<span class='line'>182</span>      * @private 
<span class='line'>183</span> 	 * @function
<span class='line'>184</span> 	 * @description Detecta um trecho de silencio nos buffers capturados de audio.
<span class='line'>185</span> 	 * @param {ChannelData} left Objeto que contem dados do canal esquerdo (L).
<span class='line'>186</span> 	 * @param {ChannelData} right Objeto que contem dados do canal direito (R).
<span class='line'>187</span> 	 * @param {Number} dbSilence Nivel de silencio, em dB.
<span class='line'>188</span> 	 * @param {Number} lenSilence Duracao de silencio, em ms.
<span class='line'>189</span> 	 * @returns {Boolean} True se os buffers contem um trecho de silencio.
<span class='line'>190</span>      */</span><span class="WHIT">
<span class='line'>191</span> </span><span class="WHIT">	</span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">detectSilence</span><span class="PUNC">(</span><span class="NAME">left</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">right</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dbSilence</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">lenSilence</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>192</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">lBuf</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Float32Array</span><span class="PUNC">(</span><span class="NAME">left</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>193</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rBuf</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Float32Array</span><span class="PUNC">(</span><span class="NAME">right</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>194</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">mono</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">resampleMonoByX</span><span class="PUNC">(</span><span class="NAME">lBuf</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">rBuf</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">RESAMPLE_FACTOR</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>195</span> </span><span class="WHIT">	    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">len</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">mono.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>196</span> </span><span class="WHIT">	    </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">len</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>197</span> </span><span class="WHIT">	    	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">isSilence</span><span class="PUNC">(</span><span class="NAME">mono</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NUMB">0x7FFF</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">32767</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dbSilence</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> 
<span class='line'>198</span> 	    		</span><span class="NAME">silenceFrames</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>199</span> </span><span class="WHIT">	    		</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">status</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">status</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>200</span> </span><span class="WHIT">	    		</span><span class="KEYW">break</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>201</span> </span><span class="WHIT">	    	</span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">status</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>202</span> </span><span class="WHIT">	    		</span><span class="NAME">silenceFrames</span><span class="PUNC">++</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>203</span> </span><span class="WHIT">	    	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>204</span> </span><span class="WHIT">	    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>205</span> </span><span class="WHIT">	    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">silenceNeedFrames</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">sampleRate</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">RESAMPLE_FACTOR</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">lenSilence</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">1000.0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>206</span> </span><span class="WHIT">	    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">hasSilence</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">silenceFrames</span><span class="WHIT"> </span><span class="PUNC">>=</span><span class="WHIT"> </span><span class="NAME">silenceNeedFrames</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> 
<span class='line'>207</span> 	    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">hasSilence</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">status</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">status</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>208</span> </span><span class="WHIT">	    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">status</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>209</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>210</span> </span><span class="WHIT">	
<span class='line'>211</span>     </span><span class="COMM">/** 
<span class='line'>212</span>      * @private 
<span class='line'>213</span> 	 * @function
<span class='line'>214</span> 	 * @description Retorna se uma amostra de audio (1 sample) representa silencio.
<span class='line'>215</span> 	 * @param {Number} data Amostra (1 sample).
<span class='line'>216</span> 	 * @param {Number} peek Valor maximo de pico possivel para a amostra.
<span class='line'>217</span> 	 * @param {Number} dbSilence Nivel de silencio, em dB.
<span class='line'>218</span> 	 * @returns {Boolean} True se a amostra contem silencio.
<span class='line'>219</span>      */</span><span class="WHIT">
<span class='line'>220</span> </span><span class="WHIT">	</span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">isSilence</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">peek</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dbSilence</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>221</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">dbRMS</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">10.0</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.log</span><span class="PUNC">(</span><span class="NAME">Math.abs</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">)</span><span class="PUNC">/</span><span class="NAME">peek</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">Math.LN10</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>222</span> </span><span class="WHIT">		</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">dbRMS</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">dbSilence</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">data</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">				
<span class='line'>223</span> 		</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>224</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>225</span> 
<span class='line'>226</span> </span><span class="WHIT">    </span><span class="COMM">/** 
<span class='line'>227</span>      * @private 
<span class='line'>228</span> 	 * @function
<span class='line'>229</span> 	 * @description Grava dados de audio (RAW PCM) para o formato WAV.
<span class='line'>230</span> 	 * @param {Raw} left Buffer com dados do canal esquerdo (L).
<span class='line'>231</span> 	 * @param {Raw} right Buffer com dados do canal direito (R).
<span class='line'>232</span> 	 * @param {Number} reclen Tamanho do buffer de audio.
<span class='line'>233</span> 	 * @param {Number} srate Taxa de amostragem, em Hz.
<span class='line'>234</span> 	 * @returns {DataView} Objeto que contem dados no formato WAV.
<span class='line'>235</span>      */</span><span class="WHIT">
<span class='line'>236</span> </span><span class="WHIT">	</span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">pcmToWav</span><span class="PUNC">(</span><span class="NAME">left</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">right</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">reclen</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">srate</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>237</span> </span><span class="WHIT">		</span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>238</span> </span><span class="WHIT">			</span><span class="NAME">leftBuffer</span><span class="WHIT">  </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">mergeBuffers</span><span class="PUNC">(</span><span class="NAME">left</span><span class="WHIT"> </span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">reclen</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>239</span> </span><span class="WHIT">			</span><span class="NAME">rightBuffer</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">mergeBuffers</span><span class="PUNC">(</span><span class="NAME">right</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">reclen</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>240</span> </span><span class="WHIT">			</span><span class="NAME">monoBuffer</span><span class="WHIT">  </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">resampleMonoByX</span><span class="PUNC">(</span><span class="NAME">leftBuffer</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">rightBuffer</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">RESAMPLE_FACTOR</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>241</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">catch</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>242</span> </span><span class="WHIT">	    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">monoLen</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">monoBuffer.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>243</span> </span><span class="WHIT">	    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">silenceFrames</span><span class="WHIT"> </span><span class="PUNC">>=</span><span class="WHIT"> </span><span class="NAME">monoLen</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>244</span> </span><span class="WHIT">	    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">buffer</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">ArrayBuffer</span><span class="PUNC">(</span><span class="NUMB">44</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">monoBuffer.length</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>245</span> </span><span class="WHIT">	    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">DataView</span><span class="PUNC">(</span><span class="NAME">buffer</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>246</span> </span><span class="WHIT">	    </span><span class="COMM">// RIFF chunk descriptor</span><span class="WHIT">
<span class='line'>247</span> </span><span class="WHIT">	    </span><span class="NAME">writeUTFBytes</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'RIFF'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>248</span> </span><span class="WHIT">	    </span><span class="NAME">data.setUint32</span><span class="PUNC">(</span><span class="NUMB">4</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">44</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">monoLen</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>249</span> </span><span class="WHIT">	    </span><span class="NAME">writeUTFBytes</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">8</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'WAVE'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>250</span> </span><span class="WHIT">	    </span><span class="COMM">// FMT sub-chunk</span><span class="WHIT">
<span class='line'>251</span> </span><span class="WHIT">	    </span><span class="NAME">writeUTFBytes</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">12</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'fmt '</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>252</span> </span><span class="WHIT">	    </span><span class="NAME">data.setUint32</span><span class="PUNC">(</span><span class="NUMB">16</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">16</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>253</span> </span><span class="WHIT">	    </span><span class="NAME">data.setUint16</span><span class="PUNC">(</span><span class="NUMB">20</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>254</span> </span><span class="WHIT">	    </span><span class="COMM">// mono (1 channel)</span><span class="WHIT">
<span class='line'>255</span> </span><span class="WHIT">	    </span><span class="NAME">data.setUint16</span><span class="PUNC">(</span><span class="NUMB">22</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>256</span> </span><span class="WHIT">	    </span><span class="NAME">data.setUint32</span><span class="PUNC">(</span><span class="NUMB">24</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">srate</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">RESAMPLE_FACTOR</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>257</span> </span><span class="WHIT">	    </span><span class="NAME">data.setUint32</span><span class="PUNC">(</span><span class="NUMB">28</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">srate</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">RESAMPLE_FACTOR</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>258</span> </span><span class="WHIT">	    </span><span class="NAME">data.setUint16</span><span class="PUNC">(</span><span class="NUMB">32</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>259</span> </span><span class="WHIT">	    </span><span class="NAME">data.setUint16</span><span class="PUNC">(</span><span class="NUMB">34</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">16</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>260</span> </span><span class="WHIT">	    </span><span class="COMM">// data sub-chunk</span><span class="WHIT">
<span class='line'>261</span> </span><span class="WHIT">	    </span><span class="NAME">writeUTFBytes</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">36</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'data'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>262</span> </span><span class="WHIT">	    </span><span class="NAME">data.setUint32</span><span class="PUNC">(</span><span class="NUMB">40</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">monoLen</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>263</span> </span><span class="WHIT">	    </span><span class="COMM">// write the PCM samples</span><span class="WHIT">
<span class='line'>264</span> </span><span class="WHIT">	    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">index</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">44</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>265</span> </span><span class="WHIT">	    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">volume</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>266</span> </span><span class="WHIT">	    </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">monoLen</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>267</span> </span><span class="WHIT">	    	</span><span class="NAME">data.setInt16</span><span class="PUNC">(</span><span class="NAME">index</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">monoBuffer</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">0x7FFF</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">volume</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>268</span> </span><span class="WHIT">	        </span><span class="NAME">index</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>269</span> </span><span class="WHIT">	    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>270</span> </span><span class="WHIT">	    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>271</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>272</span> </span><span class="WHIT">	
<span class='line'>273</span>     </span><span class="COMM">/** 
<span class='line'>274</span>      * @private 
<span class='line'>275</span> 	 * @function
<span class='line'>276</span> 	 * @description Reamostra e realiza mix de dois canais, resultando em
<span class='line'>277</span> 	 *   um canal mono com taxa de amostragem com valor de 1/X do original.
<span class='line'>278</span> 	 * @param {Float32Array} left Buffer com dados do canal esquerdo (L).
<span class='line'>279</span> 	 * @param {Float32Array} right Buffer com dados do canal direito (R).
<span class='line'>280</span> 	 * @param {Number} x Fator de reamostragem (2: metade; 4: um quarto, etc).
<span class='line'>281</span> 	 * @returns {Float32Array} Buffer de um canal (mono) com taxa reamostrada.
<span class='line'>282</span>      */</span><span class="WHIT">
<span class='line'>283</span> </span><span class="WHIT">	</span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">resampleMonoByX</span><span class="PUNC">(</span><span class="NAME">left</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">right</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>284</span> </span><span class="WHIT">		</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>285</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">len</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">left.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>286</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">result</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Float32Array</span><span class="PUNC">(</span><span class="NAME">len</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>287</span> </span><span class="WHIT">		</span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">j</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">len</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">j</span><span class="PUNC">+</span><span class="PUNC">=</span><span class="NAME">x</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>288</span> </span><span class="WHIT">			</span><span class="NAME">result</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">left</span><span class="PUNC">[</span><span class="NAME">j</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">right</span><span class="PUNC">[</span><span class="NAME">j</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">;</span><span class="WHIT"> 
<span class='line'>289</span> 		</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>290</span> </span><span class="WHIT">		</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">result</span><span class="PUNC">;</span><span class="WHIT"> 
<span class='line'>291</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>292</span> 
<span class='line'>293</span> </span><span class="WHIT">    </span><span class="COMM">/** 
<span class='line'>294</span>      * @private 
<span class='line'>295</span> 	 * @function
<span class='line'>296</span> 	 * @description Une todos os buffers de audio capturados por getUserMedia().
<span class='line'>297</span> 	 * @param {Array} channelBuf Buffer com dados de um canal.
<span class='line'>298</span> 	 * @param {Number} reclen Comprimento do buffer.
<span class='line'>299</span> 	 * @returns {Float32Array} Buffer unificado de um canal.
<span class='line'>300</span>      */</span><span class="WHIT">
<span class='line'>301</span> </span><span class="WHIT">	</span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">mergeBuffers</span><span class="PUNC">(</span><span class="NAME">channelBuf</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">reclen</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>302</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">result</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Float32Array</span><span class="PUNC">(</span><span class="NAME">reclen</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>303</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">offset</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>304</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">lng</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">channelBuf.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>305</span> </span><span class="WHIT">		</span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">lng</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>306</span> </span><span class="WHIT">			</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">buffer</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">channelBuf</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>307</span> </span><span class="WHIT">		    </span><span class="NAME">result.set</span><span class="PUNC">(</span><span class="NAME">buffer</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">offset</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>308</span> </span><span class="WHIT">		    </span><span class="NAME">offset</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">buffer.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>309</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>310</span> </span><span class="WHIT">		</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">result</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>311</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>312</span> </span><span class="WHIT">	
<span class='line'>313</span>     </span><span class="COMM">/** 
<span class='line'>314</span>      * @private 
<span class='line'>315</span> 	 * @function
<span class='line'>316</span> 	 * @description Escreve uma string em um DataView, usando UTF-8.
<span class='line'>317</span> 	 * @param {DataView} dview Objeto DataView.
<span class='line'>318</span> 	 * @param {Number} offset Posicao de escrita no DataView.
<span class='line'>319</span> 	 * @param {String} string Texto a ser escrito no DataView.
<span class='line'>320</span>      */</span><span class="WHIT">
<span class='line'>321</span> </span><span class="WHIT">	</span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">writeUTFBytes</span><span class="PUNC">(</span><span class="NAME">dview</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">offset</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">string</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT"> 
<span class='line'>322</span> 		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">lng</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">string.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>323</span> </span><span class="WHIT">		</span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">lng</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>324</span> </span><span class="WHIT">			</span><span class="NAME">dview.setUint8</span><span class="PUNC">(</span><span class="NAME">offset</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">string.charCodeAt</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>325</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>326</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>327</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>328</span> </span></pre></body></html>